home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
fish
/
001-100
/
001-025
/
019
/
blackjack
/
dekmgr.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-17
|
1KB
|
77 lines
/* DEKMGR.C deck manager
*/
#include "local.h"
#include "bj.h"
#include "dekmgr.h"
#define NCARDS (4 * 52)
static short deck[NCARDS] = {0}; /* the deck */
static short nc = 0; /* subscript of next card */
static short shufpt = 0; /* subscript of shuffle point */
/* deklow - is deck at or past shuffle point ?
*/
bool deklow()
{
return (shufpt <= nc);
}
/* opndck - initialize the deck
*/
void opndek()
{
short varnum();
void shuffl();
void srand();
short i;
short low;
for (low = 0; low < NCARDS; low += 52)
for (i = 0; i < 52; ++i)
deck[i + low] = i;
srand((unsigned)varnum());
shuffl();
}
/* shuffl - shuffle the deck
*/
void shuffl()
{
short t; /* temporary for swap */
short i; /* index for loop over cards */
short j; /* index for swap */
short nfrom(); /* fn to produce random number */
for (i = 0; i < NCARDS; ++i) {
j = nfrom(i, NCARDS - 1);
t = deck[j], deck[j] = deck[i], deck[i] = t;
}
shufpt = nfrom(NCARDS - 52, NCARDS - 36);
nc = 0;
printf("Shuffle\n");
}
/* tkcard - take a card
*/
short tkcard()
{
void shuffl();
if (NCARDS <= nc) shuffl();
return(deck[nc++]);
}
/* varnum - returns a varying startoff number
*/
short varnum()
{
int rand();
return((short)rand());
}